package org.com.creationalPattern.prototypePattern;

import java.util.Random;
/**
 * @author Jonny
 * @version 1.0
 * @Description:
 * @date 2021/4/14 16:45
 */
public class ClientDemo {
    private static int MAX_COUNT=6;

    public static void main(String[] args) {
        int i=0;
        Mail mail=new Mail("某商城五一节活动","五一抽奖活动：凡五一期间购买商品满500打骨折！");
        mail.setTail("解释权归JONNY所有");
        while(i<MAX_COUNT){
            Mail cloneMail=mail.clone();
            cloneMail.setAppellation(getRandString(5)+"先生/女士");
            cloneMail.setReceiver(getRandString(11)+"@mail.com");
            SendMail(cloneMail);
            i++;
        }
    }

    private static void SendMail(Mail cloneMail) {
        System.out.println("标题："+cloneMail.getSubject()+"\n"+
                "收件人："+cloneMail.getReceiver()+"\n"
                );
    }

    private static String getRandString(int length) {
        String str="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        Random random=new Random();
        StringBuffer sb=new StringBuffer();
        for(int i=0;i<length;i++){
            int number=random.nextInt(62);
            sb.append(str.charAt(number));
        }
        return sb.toString();
    }
}
